package com.example.demo.service.impl;


import com.example.demo.common.ServerResponse;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public ServerResponse<User> queryById(String id) {
        User user=userMapper.queryById(id);
        if(user ==null){
            return ServerResponse.failWithMsg("no user found");
        }
        return ServerResponse.succWithMsgData("user found",user);
    }

    @Override
    public ServerResponse<List> queryAll() {
        List<User> list= userMapper.queryAll();
        return ServerResponse.succWithMsgData("find all",list);
    }

    @Override
    public ServerResponse<String> add(User user) {
        userMapper.add(user);
        return null;
    }

    @Override
    public ServerResponse<User> updateById(User user) {
        userMapper.updateById(user);
        return null;
    }

    @Override
    public ServerResponse<String> delById(String id) {
        String a= userMapper.delById(id) ==1 ? "sccess" : "shibai";
        return ServerResponse.succWithMsgData("jsdf",a);
    }
}
